package com.zy.edu.config;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.zy.edu.bean.Classinfo;
import com.zy.edu.bean.Jurisdiction;
import com.zy.edu.bean.School;
import com.zy.edu.config.ali.AliVideo;
import com.zy.edu.service.*;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.stereotype.Component;
import org.springframework.util.StringUtils;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author: HuangHaiShui
 * @description:
 * @date: 2021/7/16 14:40
 * @version: 1.0
 */
@Component
public class ApplicationRunnerImpl implements ApplicationRunner {

    @Resource
    SchoolService schoolService;

    @Resource
    JurisdictionService jurisdictionService;

    @Resource
    ClassinfoService classinfoService;

    @Resource
    DataConfigService dataConfigService;

    @Resource
    CourseTypeService courseTypeService;

    @Override
    public void run(ApplicationArguments args) throws Exception {


        List<Jurisdiction> jurisList = jurisdictionService.selectList(new EntityWrapper<Jurisdiction>()
                .eq("status",1));
        for (Jurisdiction jurisdiction : jurisList) {
            SystemParam.JURISDICTIONS.put(jurisdiction.getId(),jurisdiction.getName());
        }
        courseTypeService.initSystemData();
        schoolService.initSystemData();

        classinfoService.initSystemData();

        String aliKeyId = dataConfigService.getValueByName("aliKeyId");
        if(!StringUtils.isEmpty(aliKeyId)){
            AliVideo.KeyId = aliKeyId;
        }

        String aliKeySecret = dataConfigService.getValueByName("aliKeySecret");
        if(!StringUtils.isEmpty(aliKeySecret)) {
            AliVideo.KeySecret = aliKeySecret;
        }
        String aliRegionId = dataConfigService.getValueByName("aliRegionId");
        if(!StringUtils.isEmpty(aliRegionId)) {
            AliVideo.RegionId = aliRegionId;
        }
//        String aliKeyToken = dataConfigService.getValueByName("aliKeyToken");
//        if(!StringUtils.isEmpty(aliKeyToken)) {
//            AliVideo.SecurityToken = aliKeyToken;
//        }
    }
}
